package entidadesBD;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import entidadesVO.*;

@Entity
@Table(name = "articulos_sol_dist")
public class ArticulosSolDist implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Articulo articulo;
	private int cantidad;
	private Tienda tienda;
	private SolDist solDist;
	
	private int codigoArticulosSolDist;

	public ArticulosSolDist(Articulo articulo, int cantidad, Tienda tienda) {
		this.articulo = articulo;
		this.cantidad = cantidad;
		this.tienda = tienda;
	}
	/*
	 * Constructor Vacio
	 */
	public ArticulosSolDist(){
	
	}
	
	@OneToOne
	@JoinColumn(name = "articulo")
	public Articulo getArticulo() {
		return articulo;
	}
	public void setArticulo(Articulo articulo) {
		this.articulo = articulo;
	}
	
	@Column
	public int getCantidad() {
		return cantidad;
	}
	public void setCantidad(int cantidad) {
		this.cantidad = cantidad;
	}
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public int getCodigoArticulosSolDist() {
		return codigoArticulosSolDist;
	}
	public void setCodigoArticulosSolDist(int codigoArticulosSolDist) {
		this.codigoArticulosSolDist = codigoArticulosSolDist;
	}
	
	@OneToOne
	@JoinColumn(name = "tienda")
	public Tienda getTienda() {
		return tienda;
	}
	public void setTienda(Tienda tienda) {
		this.tienda = tienda;
	}
	
	@ManyToOne
	public SolDist getSolDist() {
		return solDist;
	}
	public void setSolDist(SolDist solDist) {
		this.solDist = solDist;
	}
	
	@Transient
	public ArticulosSolDistVO getArticulosSolDistVO(){
		
		ArticuloVO articuloVO = new ArticuloVO();
		articuloVO = articulo.getArticuloVO();
		
		TiendaVO tiendaVO = new TiendaVO();
		tiendaVO = tienda.getTiendaVO();
		
		ArticulosSolDistVO articulosSolDistVO = new ArticulosSolDistVO(articuloVO, cantidad, tiendaVO);
		articulosSolDistVO.setCodigoArticulosSolDist(codigoArticulosSolDist);
		
		return articulosSolDistVO;
	}
	
	public void setArticulosSolDist(ArticulosSolDistVO articulosSolDistVO){
		
		this.cantidad = articulosSolDistVO.getCantidad();	
	}
}
